//@dart=2.12
import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/bad_event/bad_event_model.dart';

class EventArchivingViewModel extends BaseViewModel{
  dynamic id;
  EventArchivingViewModel(BuildContext? context,{this.id}) : super(context);

  var model = BadEventModel();

  PickerDataWithIdModel? controllable;

  List<PickerDataWithIdModel> controllableList = [
    PickerDataWithIdModel(pickName: '不可控',pickId: '0'),
    PickerDataWithIdModel(pickName: '可控',pickId: '1'),
  ];

  PickerDataWithIdModel? gradeLevel;
  List<PickerDataWithIdModel> gradeLevelList = [
    PickerDataWithIdModel(pickName: '1',pickId: '1'),
    PickerDataWithIdModel(pickName: '2',pickId: '2'),
    PickerDataWithIdModel(pickName: '3',pickId: '3'),
    PickerDataWithIdModel(pickName: '4',pickId: '4'),
  ];

  void chooseControllable(){
    DataPickerView(context, controllableList,currentFirstData: controllable,onSubmitListener: (p1,p2,p3){
      controllable = controllableList[p1];
      notifyListeners();
    }).show();
  }

  void chooseGradeLevel(){
    DataPickerView(context, gradeLevelList,currentFirstData: gradeLevel,onSubmitListener: (p1,p2,p3){
      gradeLevel = gradeLevelList[p1];
      notifyListeners();
    }).show();
  }

  ///事件归档
  Future<void> submitArchiving() async {
    if(controllable==null){
      showToast("请选择可控性");
      return;
    }
    if(gradeLevel==null){
      showToast('请选择事件等级');
      return;
    }
    showLoadingDialog(msg: '提交中...');
    try{
      await model.eventArchiving(id: id,controllable: controllable?.pickId,approveGrade: gradeLevel?.pickId);
      hideDialog();
      showToast('归档成功');
      finish(data: true);
    }catch(e){
      hideDialog();
      showToast(e.toNetError());
    }
  }

}